package com.campus_information_portal.dao;

import com.campus_information_portal.entity.ApplyRecheck;
import com.campus_information_portal.entity.MarkCheck;
import com.campus_information_portal.entity.StuApply;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @author 20155887 赵开兰
 * @className : MarkCheckDao
 * @Description ：成绩管理模块学生申请复查和老师处理申请Dao层
 * @create 2018/04/19
 **/
public interface MarkCheckDao {
    /**
     * @param
     * @Description: 增加一条学生申请成绩复查记录
     * @author 20155887 赵开兰
     * @methodName：addApplyScoreReCheck
     * @returnType:void
     * @methodName： addApplyScoreReCheck
     * @returnType int
     * @create 2018/4/26 15:16
     **/
    @Insert("insert into apply_recheck(applyRecheckid,stu_info_id,mark_id,stu_score_time,rescore_apply_state) " +
            "values(#{applyRecheckid},#{stu_info_id},#{mark_id},#{stu_score_time},#{rescore_apply_state})")
    int addApplyScoreReCheck(@Param("applyRecheckid") int applyRecheckid, @Param("stu_info_id") int stu_info_id,
                             @Param("mark_id") int mark_id, @Param("stu-score-time") Date stu_score_time,
                             @Param("rescore_apply_state") int rescore_apply_state);

    /**
     * @param
     * @Description: 增加一条学生申请成绩复查记录，初始申请复查状态为0
     * @author 20155887 赵开兰
     * @methodName: insertApplyRecheck
     * @returnType: int
     * @create 2018/5/3 10:42
     **/
    @Insert("insert into apply_recheck(stu_info_id,mark_id,stu_score_time,rescore_apply_state) values(#{stu_info_id}," +
            "#{mark_id},#{stu_score_time},#{rescore_apply_state})")
//values里对应的实体类的属性
    int insertApplyRecheck(ApplyRecheck applyRecheck);

    /**
     * @param: int stateupdate, @Param("applyRecheckid") int applyRecheckid
     * @Description ：老师反馈学生申请成绩复查。老师查看学生复查成绩申请，并可能进行修改成绩，将申请状态
     * 改为1（代表成绩有误，已修改）；或将申请状态改为2，代表老师已审查完毕，成绩无误.方法根据申请表id取记录
     * @author: 20155887 赵开兰
     * @methodName ：replyOfApplyScoreRecheck
     * @returnType int
     * @create 2018/5/3 14:37
     **/
    @Update("update apply_recheck set rescore_apply_state= #{rescore_apply_state} where applyRecheckid = #{applyRecheckid}")
    int replyOfApplyScoreRecheck(@Param("applyRecheckid") int applyRecheckid, @Param("rescore_apply_state") int stateupdate);

    /**
     * @param ： int MarkId,成绩ID
     * @Description :通过成绩ID查询学生ID
     * @author 20155887 赵开兰
     * @methodName :queryStuIdByMarkId
     * @returnType ：int
     * @create 2018/5/24 14:10
     **/

    @Select("select stu_info_id from mark where mark_id=#{mark_id}")
    int queryStuIdByMarkId(@Param("mark_id") int markId);

    /**
     * @param ：int markId
     * @Description : 根据MarkId查询申请复查表中有无该条成绩申请复查记录,若有记录，即返回值是1，
     * 说明该成绩已申请过了，若返回值是0，则说明可以申请复查成绩
     * @author 20155887 赵开兰
     * @methodName ：queryStateByMarkId
     * @returnType ：int
     * @create 2018/5/29 17:52
     **/
    @Select("select count(applyRecheckid) from apply_recheck where mark_id=#{mark_id}")
    int queryStateByMarkId(@Param("mark_id") int markId);


    /**
     * @param
     * @Description :老师查询所有学生的成绩复查申请记录
     * @author 20155887 赵开兰
     * @methodName ：queryAllMarkChecks
     * @returnType ： List<MarkCheck>
     * @create 2018/5/26 23:25
     **/
    @Select("select applyRecheckid,a.stu_info_id as stuId,a.mark_id as markId,a.stu_score_time as rescoreTime," +
            "rescore_apply_state as rescoreState, student.stu_name, course.course_name, m.mark from apply_recheck a," +
            " student,mark m,course where m.mark_id=a.mark_id " +
            "  and a.stu_info_id=student.stu_info_id and m.course_id=course.course_id")
    List<MarkCheck> queryAllMarkChecks();
    /*
    select applyRecheckid,a.stu_info_id as stuId,a.mark_id as markId,a.stu_score_time as rescoreTime," +
               "rescore_apply_state as rescoreState, student.stu_name, course.course_name, m.mark from apply_recheck a," +
              "student,mark m,course where m.mark_id=a.mark_id " +
             "and a.stu_info_id=student.stu_info_id and m.course_id=course.course_id
             */

}
